home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / Talking Telnet / source / debug⁄errors / debug.c next >
Text File  |  1996-06-22  |  3KB  |  109 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. ****************************************************************/
  13.  
  14. #include "vsdata.h"
  15. #include "vsinterf.proto.h"        // For VSwrite proto 
  16. #include "wind.h"                // For WindRec structure
  17. #include "parse.proto.h"        // For DemangleLinemodeShort
  18. #include "rsinterf.proto.h"        // For RSshow proto
  19. #include "linemode.proto.h"
  20. WindRec    *console;        //    Window Record (VS) for    console Window   
  21. extern WindRec    *screens;
  22.  
  23. //#define DEBUG_FACILITIES
  24.  
  25.  
  26. void InitDebug(void)
  27. {
  28. #ifdef DEBUG_FACILITIES
  29.     Rect pRect;
  30.     TerminalPrefs **termHdl;
  31.     Boolean scratchBoolean;
  32.     console = (WindRec *) myNewPtr(sizeof(WindRec));
  33.     
  34.     SetRect(&pRect, 50, 150, 700, 350);        // Need to make this a resource!
  35.     
  36.     console->vs=RSnewwindow( &pRect, 350, 80, 24,
  37.                     "\p<console>", 1, DefFONT, DefSIZE, TelInfo->debug,0,0);    /* NCSA 2.5 */
  38.  
  39.     console->wind = RSgetwindow( console->vs);
  40.     ((WindowPeek)console->wind)->windowKind = WIN_CONSOLE;
  41.  
  42.     VSwrite(console->vs,"\033[24;0H",1);        
  43.     console->active=0;
  44.     console->port=0;
  45.     console->termstate=VTEKTYPE;
  46.     console->national = 0;            /* LU: no translation */
  47.     UseResFile(TelInfo->SettingsFile);
  48.     termHdl = (TerminalPrefs **)Get1NamedResource
  49.                 (TERMINALPREFS_RESTYPE, "\p<Default>");
  50.     DetachResource((Handle) termHdl);
  51.     HLock((Handle)termHdl);
  52.     
  53.     scratchBoolean = RSsetcolor( console->vs, 0, (*termHdl)->nfcolor);
  54.     scratchBoolean = RSsetcolor( console->vs, 1, (*termHdl)->nbcolor);
  55.     scratchBoolean = RSsetcolor( console->vs, 2, (*termHdl)->bfcolor);
  56.     scratchBoolean = RSsetcolor( console->vs, 3, (*termHdl)->bbcolor);
  57.  
  58.     DisposeHandle((Handle)termHdl);
  59. #else
  60.     console = NULL;
  61. #endif
  62. }
  63.  
  64. void putln( char *cp)                                
  65. {
  66. #ifdef DEBUG_FACILITIES
  67.     short temp;
  68.     if (!TelInfo->debug)
  69.         return;
  70.  
  71.     temp=strlen(cp);
  72.     if (temp>80) return;
  73.     VSwrite(console->vs,cp,temp);
  74.     VSwrite(console->vs,"\015\012",2);
  75. #endif
  76. }
  77.  
  78. // Called by HandleKeyDown.  Allows me to insert debug info keys all in one place
  79. //    that can be easily #defined out for release versions.  Returns TRUE if
  80. //    HandleKeyDown should do an immediate return after calling us.
  81. Boolean    DebugKeys(Boolean cmddwn, unsigned char ascii, short s)
  82. {
  83. #ifdef DEBUG_FACILITIES
  84.     if (cmddwn && (ascii == ';')) {    // 2.6b16.1
  85.         char hackhackhack[80];
  86.         
  87.         strcpy(hackhackhack, "Linemode: ");
  88.         DemangleLineModeShort(hackhackhack, screens[s].lmodeBits);
  89.         putln(hackhackhack);
  90.         return(FALSE);
  91.         }
  92.     if (cmddwn && (ascii == 39)) //single quote
  93.         ShowDebugWindow();
  94.         return(FALSE);
  95. #endif
  96.     return (FALSE);
  97. }
  98.  
  99. void    ShowDebugWindow(void)
  100. {
  101. #ifdef DEBUG_FACILITIES
  102.     
  103.     if (console != NULL)
  104.     {
  105.         TelInfo->debug = TRUE;
  106.         RSshow(console->vs);
  107.     }
  108. #endif
  109. }